#coding=utf-8
'''
Created on 2015��9��12��

@author: 404158
'''
import DQArouter.xiaomi_R1D.LoginXiaoMi
import time
import DQArouter.xiaomi_R1D.logging_save
import DQArouter.xiaomi_R1D.playback
import DQArouter.xiaomi_R1D.connectmachine

def setchannel():
    try:
        DQArouter.xiaomi_R1D.logging_save.logging.info("小米路由器5G网络信道即将设为channel44")
        Driver = DQArouter.xiaomi_R1D.LoginXiaoMi.Login()
        Driver.implicitly_wait(10)
        Driver.find_element_by_xpath("/html/body/div[1]/div[2]/div/ul/li[3]/a/span").click()
        time.sleep(1)
        Driver.find_element_by_xpath("//a[@href='#!pro/wifi_set']").click()
        time.sleep(2)
        Driver.switch_to_frame("setting")
        Driver.find_element_by_xpath("/html/body/div[1]/div[2]/div[3]/form/div[2]/span/input").click()        
        Driver.find_element_by_xpath("/html/body/div[4]/a[4]").click()
        time.sleep(2)
        Driver.switch_to_default_content()
        Driver.find_element_by_xpath("/html/body/div[1]/div/div[3]/div/a[1]/span").click()
        time.sleep(2)
        Driver.switch_to_frame("setting")
        Driver.find_element_by_xpath("/html/body/div[1]/div[2]/div[3]/form/div[6]/button").click()
        time.sleep(1)
        Driver.switch_to_default_content()
        Driver.find_element_by_xpath("/html/body/div[1]/div/div[3]/div/a[1]/span").click()
        time.sleep(20)
        Driver.quit()
        DQArouter.xiaomi_R1D.logging_save.logging.info("小米路由器5G网络信道已经设为channel44")
    except:
        Driver.quit()
        time.sleep(3)
        setchannel()
    
def run():
    setchannel()
    time.sleep(30)
    result = DQArouter.xiaomi_R1D.playback.PlaySong()
    if result == 'ok':
        return 'reconnect_succeed'
    else:
        LogPath = DQArouter.xiaomi_R1D.connectmachine.ConnectFive('fiveG_channel44')
        result = DQArouter.xiaomi_R1D.playback.PlaySong()
        return LogPath
        
if __name__ == '__main__':
    run()